<?php
echo $html->css ( 'tab' );
echo $html->css ( 'style' );
echo $javascript->link('jquery-1.4.2');
echo $html->css('start/jquery-ui-1.8.2.custom');
echo $javascript->link('jquery-ui-1.8.2.custom.min');
echo $html->css ( 'jquery-validate/css/screen' );
echo $javascript->link ( 'jquery-validate/jquery.validate');
echo $javascript->link ( 'jquery-validate/additional-methods');
echo $javascript->link ( 'jquery-validate/localization/messages_cn');

?>

<script type="text/javascript">
//添加验证
$(document).ready(function() {
	$.validator.setDefaults({       
		 submitHandler: function(form) {    
		  form.submit();    
		}       
	});   
			
	$("#LeaveRequestForm").validate({
		rules: {
		"data[Leave][start]" :{
			required: true
			},//主题
		"data[Leave][end]" :{
			required: true
			},//主题
		"data[Leave][checkers]" :{
			required: true,stringMinLength:0,stringMaxLength:100
			},//主题
		"data[Leave][emails]" :{
			required: true,email:true
			},//主题
		"data[Leave][title]" :{
			required: true,stringMinLength:0,stringMaxLength:100
			},//主题
		"data[Leave][content]"  :{
			required: false
			}//内容
		},
		messages:{},
		focusInvalid:false,
		onkeyup:false,
		errorPlacement:function(error, element){error.appendTo(element.parent());}
	});
});
//验证结束
</script>
 
<script type="text/javascript">
	$(function(){
		$(".datepickerSpan :input").datepicker({
			inline: true
		});
		 $('.datepickerSpan :input').datepicker('option', {dateFormat: "yy-mm-dd"});
		 $('.datepickerSpan :input').datepicker( "option", "closeText", 'X' );
	});
	$(function()
	{
		$("#close").click(function(){
			window.close();							
		});
		$('#closePop').click(function(){
			$(".toolbarStyle").toggle();
		});
	});
	function showCheckers() {
		$(".toolbarStyle").toggle();
	}
	function changeCheckers(organ) {
		var checkers = jQuery.parseJSON('<?php echo $checkers; ?>');
		var html = '';
		if (undefined != checkers[organ]) {
			html += '<tr>';
			for (var i = 0; i < checkers[organ].length; i++) {
				if (i > 0 && i % 5 == 0) {
					html += '</tr><tr>';
				}
				html += '<td><input type="checkbox" alt="' + i + '" name="checker" onchange="cancelCheck(this.alt);" value="' + checkers[organ][i].username + ',' + checkers[organ][i].email + '" />&nbsp;' + checkers[organ][i].name + '</td>';
			}
			html += '</tr>';
		}
		$('#ctable').html(html);
	}
	function cancelCheck(alt) {
		$('input[name=checker]').each(function(){
			if (true == $(this).attr('checked') && $(this).attr('alt') != alt) {
				$(this).attr('checked', false);
			}
		});
	}
	function selectCheckers() {
		var checkers = '';
		var emails = '';
		$('input[name=checker]').each(function(){
			if (true == $(this).attr('checked')) {
				var arr = $(this).val().split(',');
				if ('' != checkers) {
					checkers += ',';
				}
				checkers += arr[0];
				if ('' != arr[1]) {
					if ('' != emails) {
						emails += ',';
					}
					emails += arr[1];
				}
			}
		});
		$('#LeaveCheckers').val(checkers);
		$('#LeaveEmails').val(emails);
		$(".toolbarStyle").toggle();
	}
</script>
<!-- 当前位置-->
<div id="tabmenubar">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td class="tabmenubartitle1"><?php echo  __('YourPosition');//您现在的位置：?></td>
		<td class="tabmenubartitle2"><?php echo __('Personal Office');//一级目录
										   echo '>';echo __('Leave Manage');//二级目录
										   echo '>';?>
									<?php echo $html->tag('span', __('My Leave',true));//当前操作地用span加粗?> 						  
		</td>
	</tr>
</table>
</div>
<!-- 当前位置-->

<!--选择审核人iframe-->
<div class="toolbarStyle" style="display:none;width:75%;height:400px;">
<h5>选择接收人</h5>
<table width="100%" cellspacing="0" cellpadding="0" border="0" style="text-align:left;margin-left:20px;">
	<tr>
		<td colspan=3>选择机构:
			<select onchange="changeCheckers(this.value);">
				<option value="">--无机构--</option>
			<?php
				foreach ($organs as $organ) {
					echo "<option value='{$organ['Organ']['id']}'>{$organ['Organ']['name']}</option>";
				}
			?>
			</select>
		</td>
	</tr>
	<tr>
		<td colspan=3><fieldset style="width:90%;">
			<table width="100%" cellspacing="0" cellpadding="0" border="0" id="ctable">
			</table>
		</fieldset></td>
	</tr>
	<tr>
		<td width="50"></td>
		<td width="100"><?php echo $form->button('确定',array('type'=>'button','class'=>'oksubmit','onclick'=>'selectCheckers();'));?>  <!-- __('reset', true)取消-->
		<td width="100"><?php echo $form->button('取消',array('class'=>'cancelbutton','id'=>'closePop'));?>  <!-- __('reset', true)取消-->
		</td>
	</tr>
</table>
</div>
<!--选择审核人iframe-->
 
<div class="tabflex">
<?php echo $form->create('Leave',array('action'=>'request','type'=> 'post'));?>
<fieldset>
	<legend><?php  __('Leave Info');?></legend>

<table width="100%" cellspacing="0" cellpadding="0" border="0" style="text-align: left;font-size:12px;">
	<tr>
		<td width="50"></td>
		<td width="100">请假者:</td>
		<td><?php 
				echo $form->input('creater',array('label'=>false,'value'=>$creater,'disabled'=>"disabled",'class' => 'TextBoxH'));
			?>
		</td>
		<td width="50"></td>
		<td width="100"></td>
		<td></td>
	</tr>
	<tr>
		<td width="50"></td>
		<td width="100">开始日期:<font color="red">*</font></td>
		<td><span class="datepickerSpan"><input type='text' name="data[Leave][start]" class='sitems' id="start" readonly="readonly" /></span></td>
		<td width="50"></td>
		<td width="100">结束日期:<font color="red">*</font></td>
		<td><span class="datepickerSpan"><input type='text' name="data[Leave][end]" class='sitems' id="end" readonly="readonly" /></span></td>
	</tr>
	<tr>
		<td width="50"></td>
		<td width="100">选择审核人:<font color="red">*</font></td>
		<td><?php 
				echo $form->input('checkers',array('label'=>false,'readonly'=>"readonly",'class' => 'TextBoxH','after'=>'&nbsp;<input type="button" value="选择" onclick="showCheckers();" />'));
			?>
		</td>
		<td width="50"></td>
		<td width="100">Email:<font color="red">*</font></td>
		<td><?php 
				echo $form->input('emails',array('label'=>false,'class' => 'TextBoxH'));
			?>
		</td>
	</tr>
	<tr>
		<td width="50"></td>
		<td width="100"><?php __('Subject');?>:<font color="red">*</font></td>
		<td colspan="4"><?php echo $form->input('title',array('label'=>false,'class' => 'TextBoxH'));
			?>
		</td>
	</tr>
	<tr>
		<td width="50"></td>
		<td width="100">请假内容:</td>
		<td colspan="4">
			<?php echo $form->textarea('content',array('label'=>false,'class' => 'areaStyle','size'=>4));
			?>
		</td>
	</tr>
	</table>
</fieldset>
	
	<table width="100%" cellspacing="0" cellpadding="0" border="0" style="text-align: left">
	<tr>
		<td width="50"></td>
		<td width="100"><?php echo $form->button('确定',array('type'=>'submit','class'=>'btn2'));?>  <!-- __('reset', true)取消-->
		<td width="100"><?php echo $form->button('关闭',array('class'=>'btn2','id'=>'close'));?>  <!-- __('reset', true)取消-->
		</td>
	</tr>
</table>
<?php echo $form->end();?>
</div>